package com.hksj.data.tdengine.annatation;

import com.hksj.data.tdengine.entity.Properties;
import lombok.SneakyThrows;
import org.apache.poi.ss.formula.functions.T;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zengke
 * @version 1.0
 * @see ReflectUtil
 * @since 2025/08/15 11:40
 */
public class ReflectUtil {

    @SneakyThrows
    public static <T extends java.lang.annotation.Annotation> Map<String, Object> getFieldMapAnnotatedWith(Object obj, Class<T> annotationClass) {
        Map<String, Object> map = new HashMap<>();
        if (obj == null) return map;

        Class<?> clazz = obj.getClass();
        while (clazz != null && clazz != Object.class) {
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                if (field.isAnnotationPresent(annotationClass)) {
                    field.setAccessible(true);
                    map.put(field.getName(), field.get(obj));
                }
            }
            clazz = clazz.getSuperclass(); // 向上查找父类
        }
        return map;
    }
}
